<body>
<script src="js/myJS/charge.js"></script>
<!--发票开具界面-->
<div class="modal inmodal" id="invoiceModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content animated flipInY">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h5 class="modal-title">发票信息（收费）</h5>
            </div>
            <div class="modal-body">
                <form method="post">
                    <div class="form-group  row">
                        <label class="col-sm-4 col-form-label">发票号（可修改）：</label>
                        <div class="col-sm-8"><input type="text" class="form-control" name="invoiceIDModal"></div>
                    </div>

                    <div class="form-group  row">
                        <label class="col-sm-4 col-form-label">病历号：</label>
                        <div class="col-sm-8"><input type="text" class="form-control" name="medicalRecordIDModal"></div>
                    </div>
                    <div class="form-group  row">
                        <label class="col-sm-4 col-form-label">患者姓名：</label>
                        <div class="col-sm-8"><input type="text" class="form-control" name="patientNameModal"></div>

                    </div>
                    <div class="form-group  row">
                        <label class="col-sm-4 col-form-label">支付方式：</label>
                        <div class="col-sm-8"><select class="form-control m-b" name="accountTypeModal">
                            <option selected>现金</option>
                            <option>医保卡</option>
                            <option>银行卡</option>
                            <option>信用卡</option>
                            <option>微信</option>
                            <option>支付宝</option>
                            <option>云闪付</option>
                            <option>其他</option>
                        </select>
                        </div>
                    </div>
                    <div class="form-group  row">
                        <label class="col-sm-4 col-form-label">应收金额：</label>
                        <div class="col-sm-8"><input type="text" class="form-control" name="shouldPayMoneyModal"
                                                     readonly="readonly"></div>
                    </div>
                    <div class="form-group  row">
                        <label class="col-sm-4 col-form-label">实收金额：</label>
                        <div class="col-sm-8"><input type="text" class="form-control" name="paidMoneyModal"
                        ></div>
                    </div>
                    <div class="form-group  row">
                        <label class="col-sm-4 col-form-label">找零金额：</label>
                        <div class="col-sm-8"><input type="text" class="form-control" name="exchangeModal"
                                                     readonly="readonly"></div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="submit" class="btn btn-primary" data-dismiss="modal" onclick="chargeNow()">收费</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!--收费界面-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox-title">
                <h5>患者信息查询</h5>
            </div>
            <div class="ibox-content">
                <div class="form-group  row">
                    <label class="col-sm-2 col-form-label">病历号：</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="medicalRecordID">
                        <br>
                        <button type="button" class="btn btn-w-m btn-primary" id="searchPatient"
                                onclick="searchPatient()">搜索
                        </button>
                    </div>
                </div>
            </div>

            <div class="ibox-title">
                <h5>患者信息确认</h5>
            </div>
            <div class="ibox-content">
                <div class="form-group  row">
                    <label class="col-sm-2 col-form-label">姓名：</label>
                    <div class="col-sm-10"><input type="text" class="form-control" name="name"></div>
                </div>

                <div class="form-group  row">
                    <label class="col-sm-2 col-form-label">身份证号：</label>
                    <div class="col-sm-10"><input type="text" class="form-control" name="numID"></div>
                </div>
                <div class="form-group  row">
                    <label class="col-sm-2 col-form-label">家庭住址：</label>
                    <div class="col-sm-10"><input type="text" class="form-control" name="address"></div>
                </div>
            </div>

            <div class="ibox ">
                <div class="ibox-title">
                    <h5>患者消费信息</h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <table class="table table-striped" id="chargeInfoTable">
                            <thead>
                            <tr>
                                <th><input type="checkbox" class="i-checks" name="selectAll"></th>
                                <th>病历号</th>
                                <th>姓名</th>
                                <th>项目名称</th>
                                <th>单价</th>
                                <th>数量</th>
                                <th>开立时间</th>
                                <th>状态</th>
                            </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                    <div class="form-group row">
                        <div class="col-sm-4 col-sm-offset-2">
                            <button type="button" class="btn btn-primary btn-sm" data-toggle="modal"
                                    data-target="#invoiceModal" id="openInvoiceModal">
                                收费
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    // $(document).ready(function () {
    //     $('.i-checks').iCheck({
    //         checkboxClass: 'icheckbox_square-green'
    //     });
    // });
    // $(document).ready(function () {
    //     $("#selectAll").change(function () {
    //         alert("aa");
    //         $("input[type = 'checkbox']").attr('checked', true);
    //     });
    // });
    function chargeNow() {
        let chargeUserID = [[${session.userID}]];//收费人员ID
        let chargeType = $("select[name='accountTypeModal']").val();//收费方式
        let chargeWholePrice = $("input[name = 'shouldPayMoneyModal']").val();//总价
        let invoiceID = $("input[name = 'invoiceIDModal']").val();//发票ID
        let drugPreIDs = [];//处方明细表ID

        $("input:checkbox[name=drugPreDetail]:checked").each(function () {
            let drugPreDetailID = $(this).attr("id");
            drugPreIDs.push(drugPreDetailID);
        });

        let sendJson = {};
        sendJson["chargeUserID"] = chargeUserID;
        sendJson["chargeType"] = chargeType;
        sendJson["chargeWholePrice"] = chargeWholePrice;
        sendJson["invoiceID"] = invoiceID;
        sendJson["drugPreIDs"] = drugPreIDs;

        $.ajax({
            url: "/charge",
            type: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(sendJson),
            success: function (ReturnState) {
                $('.alert').html('收费成功').addClass('alert-success').show().delay(1400).fadeOut();
                searchPatient();
            }
        });
    }

</script>
</body>